package com.ofps.forms.common.utils;


import java.util.HashMap;

/**
 * 返回数据
 * 自定义返回类
 * 返回状态码和响应消息
 * 附加请求返回信息
 */
public class R extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public R() {

    }

    public static R error() {
        return new R();
    }

    public static R error(String msg) {
        R r = new R();
        r.put("code", 500);
        r.put("message", msg);
        return r;
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.put("code", code);
        r.put("message", msg);
        return r;
    }

    public static R ok() {
        return new R();
    }

    public static R ok(int code, String msg) {
        R r = new R();
        r.put("code", code);
        r.put("message", msg);
        return r;
    }


    public static R ok(String msg) {
        R r = new R();
        r.put("code", 200);
        r.put("message", msg);
        return r;
    }


    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    @Override
    public String toString() {
        return super.toString();
    }
}
